Azure AD Authentication for Azure Python Web App

by: vijayande2018, 6 years ago


I have a Python flask web app to which I want to provide Azure AD authentication and then redirect to the template (upload.html). I tried to do this using the below python script locally on my machine but that didn't work

@app.route("/",  methods=['GET', 'POST'])  
def upload():
r = authenticate(request)
#return r
return render_template('upload.html', static_link=config.STATIC_LINK)

def authenticate(request):
# initialization
constants = config.CONSTANTS
CLIENT_ID = 'f71dbff6-a45d-4hj7-a34c-b3gh44f4d8a2'
REDIRECT_URI = 'http://localhost:5000' #'https://myapp.azurewebsites.net/'
AUTHORIZATION_BASE_URL = 'https://login.windows.net/%s/oauth2/authorize'

context = {'initialize':''}

# GET as a result of initial invocation
if request.method == 'GET':

    # create a 'requests' Oauth2Session
    azure_session = OAuth2Session(CLIENT_ID, redirect_uri=REDIRECT_URI)

    # do the outreach to https://login.windows.net/common/oauth2/authorize
    authorization_url, state = azure_session.authorization_url(AUTHORIZATION_BASE_URL % '4ae48c86-0129-4169-4561-fc121dw77bjg')
    resp = requests.get(authorization_url)      

    # go to the login page of AAD & authenticate
    return redirect(resp.url)

I wanted this app to be deployed to azure and behave the same as my local app does instead redirect to 'https://myapp.azurewebsites.net/'. I tried these links https://github.com/sebastus/azure-python-authenticate/commit/e13e74734edb57ab23ef16d1c48c7cdb762f29bf

anybody help would be highly appreciated



You must be logged in to post. Please login or register an account.